
https://leetcode.cn/problems/merge-k-sorted-lists/description/
class Solution {
public:
    struct cmp
    {
        bool operator()(const ListNode*l1,const ListNode*l2 )
        {
            return l1->val>l2->val;
        }
    };

    ListNode* mergeKLists(vector<ListNode*>& lists) {
        priority_queue<ListNode*,vector<ListNode*>,cmp> heap;

        //首元素入队列
        for(auto & l:lists)
            if(l)   heap.push(l);
        
        ListNode *newnode=new ListNode();
        ListNode*prev=newnode;
        while(!heap.empty())
        {
            ListNode*cur=heap.top();
            heap.pop();
            if(cur->next)  heap.push(cur->next);

            //处理链接
            prev->next=cur;
            prev=prev->next;
        }
        prev=newnode->next;
        delete newnode;
        return prev;
    }
};